<template>
	<view class="">
		<view class="pd pt20 pm20 z9 fz24" v-if="!form.isAuthentication">
			为确保提现正常，请按要求填写本人真实信息进行实名认证。实名认证后，，姓名和身份证信息不可修改。
		</view>
		<view class="bgff pd pt20 pm20">
			<view class="pt10 pm10 display-flex fz30 z6">
				<view class="xczvrytxctrtr vertical-center tl">
					姓名:
				</view>
				<view class="z3 flex-1">
					<input v-if="!form.isAuthentication" type="text" v-model="form.realName" class="kxcxzrtrtxr pl20" placeholder="请输入姓名" />
					<text v-else>{{form.realName}}</text>
				</view>
			</view>
			<view class="pt10 pm10 display-flex fz30 z6">
				<view class="xczvrytxctrtr vertical-center tl">
					身份证:
				</view>
				<view class="z3 flex-1">
					<input v-if="!form.isAuthentication" v-model="form.idCard" type="text" class="kxcxzrtrtxr pl20" placeholder="请输入身份证" />
					<text v-else>{{form.idCard}}</text>
				</view>
			</view>
			<view class="pt10 pm10 display-flex fz30 z6">
				<view class="xczvrytxctrtr vertical-center tl">
					籍贯:
				</view>
				<view class="z3 flex-1">
					<input v-if="!form.isAuthentication" type="text" v-model="form.idAddress" class="kxcxzrtrtxr pl20" placeholder="请输入您的籍贯地址" />
				<text v-else>{{form.idAddress}}</text>
				</view>
			</view>
			<view class="pt10 pm10 display-flex fz30 z6">
				<view class="xczvrytxctrtr vertical-center tl">
					民族:
				</view>
				<view class="z3 flex-1">
					<input v-if="!form.isAuthentication" type="text" v-model="form.nation" class="kxcxzrtrtxr pl20" placeholder="请输入您的民族" />
				<text v-else>{{form.nation||'--'}}</text>
				</view>
			</view>

		</view>

		<view class="mt100 pd" v-if="!form.isAuthentication">
			<button type="primary" class="fz32" @tap="tijiao">提交认证</button>
		</view>
	</view>
</template>
<script lang="ts" setup>
	import { ref } from "vue"
	import { upImg, hf, yzphone, callBack, dxrequestht, dxrequest } from "@/util/index.js"
	const form = ref({})
	const daoji = ref(60) //倒计时
	const jhgg = ref(true)
	const huoqus = () => {
		if (!form.value.phone) {
			uni.showToast({
				icon: "none",
				title: "请输入手机号码"
			})
			return
		}
		if (!yzphone(form.value.phone)) {
			uni.showToast({
				icon: "none",
				title: "手机号码错误"
			})
			return
		}

		if (jhgg.value == true) {
			jhgg.value = false
			daoji.value--
			var sdf_wer = setInterval(() => {
				daoji.value--
				if (daoji.value < 0) {
					daoji.value = 60
					jhgg.value = true
					clearTimeout(sdf_wer)
				}
			}, 1000)
		}
	}
	const tijiao = async () => {
		if (!form.value.realName) {
			uni.showToast({
				icon: "none",
				title: "请输入真实姓名"
			})
			return
		}
		if (!form.value.idCard) {
			uni.showToast({
				icon: "none",
				title: "请输入身份证号码"
			})
			return
		}
		if (!form.value.idAddress) {
			uni.showToast({
				icon: "none",
				title: "请输入籍贯"
			})
			return
		}
		if (!form.value.nation) {
			uni.showToast({
				icon: "none",
				title: "请输入民族"
			})
			return
		}
		
		
		uni.showLoading({
			title: "认证中..."
		})
		const kkzxcfd = await dxrequestht("https://duxinggj.com/public/faceid", {
			Name: form.value.realName,
			IdCard: form.value.idCard
		})
		uni.hideLoading()
		if (kkzxcfd.data.Result != 0) {
			uni.showToast({
				title: kkzxcfd.data.Description,
				icon: "none"
			})
			return
		}

		const ksjd = await dxrequest("/api/user", {
			...form.value,
			isAuthentication: true
		}, "put")
		if (ksjd.code == 0) {
			uni.showToast({
				title: "提交成功！!"
			})
			callBack()
		}


	}
	const getuser = async () => {
		const openid = uni.getStorageSync("openid")
		const { data } = await dxrequest("/api/user/" + openid)
		form.value = data
	
	}
	getuser()
</script>

<style scoped>
</style>